package com.multiplayer.service.impl;

import java.util.List;

import com.multiplayer.dao.ISeatDao;
import com.multiplayer.dao.IStudyRoomDao;
import com.multiplayer.dao.impl.SeatDaoImpl;
import com.multiplayer.dao.impl.StudyRoomDaoImpl;
import com.multiplayer.entity.Seat;
import com.multiplayer.service.ISeatService;
import com.multiplayer.tools.PageData;




public class SeatServiceImpl implements ISeatService{
	ISeatDao seatDao=new SeatDaoImpl();
	/**
	 * 批量添加座位
	 */
	@Override
	public boolean addSeat(int seatsNum, String studyroomId) {
		// TODO Auto-generated method stub
		//如果不存在该自习室，则添加座位失败
		IStudyRoomDao studyRoomDao=new StudyRoomDaoImpl();
		if(studyRoomDao.queryStudyRoomById(studyroomId).size()==0)
		{
			return false;
		}
		if(seatDao.addSeat(seatsNum, studyroomId))
		{
			return true;
		}
		else
		{
			return false;
		}
		
	}

	/**
	 * 批量删除座位
	 */
	@Override
	public boolean deleteSeatByNum(int seatsNum, String studyroomId) {
		// TODO Auto-generated method stub
		//如果不存在该自习室，则删除座位失败
		IStudyRoomDao studyRoomDao=new StudyRoomDaoImpl();
		if(studyRoomDao.queryStudyRoomById(studyroomId).size()==0)
		{
			return false;
		}
		if(seatDao.deleteSeatByNum(seatsNum, studyroomId))
		{
			return true;
		}
		else
		{
			return false;
		}
		
	}

	/**
	 * 通过座位编号删除座位
	 */
	@Override
	public boolean deleteSeatById(String seatId){
		// TODO Auto-generated method stub
		if(seatDao.deleteSeatById(seatId))
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	/**
	 * 修改座位信息
	 */
	@Override
	public boolean editSeat(Seat seat) {
		// TODO Auto-generated method stub
		//如果不存在该自习室，则修改座位失败
		IStudyRoomDao studyRoomDao=new StudyRoomDaoImpl();
		if(studyRoomDao.queryStudyRoomById(seat.getRno()).size()==0)
		{
			return false;
		}
		//如果不存在该座位，则修改座位失败
		if(seatDao.querySeatByKeywords(seat.getEseatno()).size()==0)
		{
			return false;
		}

		if(seatDao.editSeat(seat))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	/**
	 * 模糊查询座位信息
	 */
	@Override
	public List<Seat> querySeatByKeywords(String keywords) {
		// TODO Auto-generated method stub
		List<Seat> list=seatDao.querySeatByKeywords(keywords);
		return list;
	}
	/**
	 * 通过模糊查询分页显示座位信息
	 */
	@Override
	public PageData<Seat> getSeatByPage(int page, int pageSize, String keywords) {
		// TODO Auto-generated method stub
		//当前页码不能小于1
		if(page<1)
		{
			page=1;
		}
		PageData<Seat> pd=seatDao.getSeatByPage(page, pageSize,keywords);
		return pd;
	}

}
